<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Models\Tag;
use App\Models\Pictuer;

class LikeController extends Controller
{
    public function __construct()
    {
        $this->middleware('api.auth');
    }
    // 存储一个 喜欢 （点赞接口）
    public function store($id, $type = 'pictuer')
    {
        $user = $this->user();
        switch ($type) {
            case 'tag':
            $model = Tag::find($id);
            break;
            default:
            $model = Pictuer::find($id);
        }
        $user->like($model);
        return $this->response->noContent();
    }

    // 取消点赞
    public function destroy($id, $type = 'pictuer')
    {
        $user = $this->user();
        switch ($type) {
            case 'tag':
            $model = Tag::find($id);
            break;
            default:
            $model = Pictuer::find($id);
        }
        $user->unlike($model);
        return $this->response->noContent();
    }
}
